from tools.listNode import listToNode


def isPalindrome(head):
    if not head:
        return True
    stack = []
    temp = head
    while temp:
        stack.append(temp.val)
        temp = temp.next
    while stack and head:
        if stack.pop() != head.val:
            return False
        head = head.next
    return True


print(isPalindrome(listToNode([1, 2, 3])))
print(isPalindrome(listToNode([1, 2, 2, 1])))
print(isPalindrome(listToNode([1, 2, 1])))
